//css_reference "core.dll";
//css_reference "Databases.dll";
//css_reference "utils.dll";
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Net;
using System.Collections;
using System.Web;
using System.Text.RegularExpressions;
using MediaPortal.Util;
class Grabber : MediaPortal.Video.Database.IIMDBScriptGrabber
{
public Grabber()
{
}
void MediaPortal.Video.Database.IIMDBScriptGrabber.FindFilm(string strSearch, int iLimit, ArrayList elements)
{
int iCount = 0;
string strTitle;
try
{
string absoluteUri;
string strURL = "http://www.edb.co.il/Find.php?q=" + strSearch;
string strBody = GetPage(strURL, "windows-1255", out absoluteUri);
int iStartOfMovieList = strBody.IndexOf("כותרים נפוצים");
if (iStartOfMovieList < 0)
{
return;
}
int iEndOfMovieList = strBody.IndexOf("
", iStartOfMovieList);
if (iEndOfMovieList < 0)
{
iEndOfMovieList = strBody.Length;
}
strBody = strBody.Substring(iStartOfMovieList, iEndOfMovieList - iStartOfMovieList);
while ((true) && (iCount < iLimit))
{
////Lord of the Rings: The Two Towers, The (2002)
int iAHREF = strBody.IndexOf("");
if (iEndAHREF >= 0)
{
iAHREF += "");
if (iURL > 0)
{
strTitle = "";
strURL = strAHRef.Substring(0, iURL);
if (strURL[strURL.Length - 1] == '\'')
strURL = strURL.Substring(0, strURL.Length - 1);
iURL+="".Length + 1;
int iURLEnd = strAHRef.IndexOf("", iURL);
if (iURLEnd > 0)
{
strTitle = strAHRef.Substring(iURL, iURLEnd - iURL);
iURLEnd = strAHRef.IndexOf("(", iURLEnd);
if (iURLEnd > 0)
{
iURL = iURLEnd;
iURLEnd = strAHRef.IndexOf(")", iURLEnd);
if (iURLEnd > 0)
{
strTitle+= " " + strAHRef.Substring(iURL, iURLEnd - iURL + 1);
}
}
}
else
strTitle = strAHRef.Substring(iURL);
strURL = String.Format("http://www.edb.co.il{0}", strURL);
HTMLUtil htmlUtil = new HTMLUtil();
htmlUtil.ConvertHTMLToAnsi(strTitle, out strTitle);
int endTagLength = "".Length;
int posNextTag = strBody.IndexOf("<", iEndAHREF + endTagLength);
if (posNextTag > 0)
{
string strSub = strBody.Substring(iEndAHREF + endTagLength, posNextTag - (iEndAHREF + endTagLength));
strTitle += strSub;
}
// to avoid including of
if ((strTitle.IndexOf("\n") < 0) && (strTitle.IndexOf(" ") < 0))
{
MediaPortal.Video.Database.IMDB.IMDBUrl url = new MediaPortal.Video.Database.IMDB.IMDBUrl(strURL, strTitle + " - מתוך edb.co.il", "edb_co_il");
elements.Add(url);
}
iCount++;
}
if (iEndAHREF + 1 >= strBody.Length)
break;
iStartOfMovieList = iEndAHREF + 1;
strBody = strBody.Substring(iEndAHREF + 1);
}
else
{
break;
}
}
else
{
break;
}
}
}
catch (Exception ex)
{
MediaPortal.GUI.Library.Log.Error("exception for edb lookup of {0} err:{1} stack:{2}",strSearch, ex.Message, ex.StackTrace);
}
}
bool MediaPortal.Video.Database.IIMDBScriptGrabber.GetDetails(MediaPortal.Video.Database.IMDB.IMDBUrl url, ref MediaPortal.Video.Database.IMDBMovie movieDetails)
{
try
{
int iStart = 0;
int iEnd = 0;
movieDetails.Reset();
// add databaseinfo
// may add an another grabber
movieDetails.Database = "edb_co_il";
string strAbsURL;
string strBody = GetPage(url.URL, "windows-1255", out strAbsURL);
if (strBody == null || strBody.Length == 0)
return false;
// IMDBNumber
int iPos = strAbsURL.IndexOf("/titles/");
if (iPos > 0)
{
iPos += "/titles/".Length;
movieDetails.IMDBNumber = strAbsURL.Substring(iPos);
int pos = movieDetails.IMDBNumber.IndexOf("/");
if (pos > 0)
movieDetails.IMDBNumber = movieDetails.IMDBNumber.Substring(0, pos);
}
// Title
url.Title = url.Title.Trim();
iEnd = url.Title.IndexOf("(");
if (iEnd >= 0)
{
int yearEnd = url.Title.IndexOf(")");
if (yearEnd >= 0)
{
try
{
movieDetails.Year = int.Parse(url.Title.Substring(iEnd+1, yearEnd - iEnd - 1));
}
catch (Exception)
{
}
}
movieDetails.Title = url.Title.Substring(0, iEnd);
}
else
movieDetails.Title = url.Title;
string RegTitleBlock = "
(.*)
"; Match titleBlock = Regex.Match(strBody, RegTitleBlock); if (titleBlock.Success) { // I used the MPARating string as a subtitle (because it appears in the mediaportal below the title) movieDetails.MPARating = movieDetails.Title.Trim(); movieDetails.PlotOutline = movieDetails.Title.Trim(); movieDetails.Title = titleBlock.Groups[1].Value; } else { movieDetails.Title = movieDetails.Title.Trim(); movieDetails.PlotOutline = movieDetails.Title.Trim(); } movieDetails.TagLine = ""; // Plot String PLOT_START="זמן ריצה: (\\d*) דקות.
"; Match runtimeBlock = Regex.Match(strBody, RUNTIME_REG); if (runtimeBlock.Success) { try { movieDetails.RunTime = int.Parse(runtimeBlock.Groups[1].Value); } catch (Exception ex3) { MediaPortal.GUI.Library.Log.Error("exception for edb lookup of {0} err:{1} stack:{2}", url.URL, ex3.Message, ex3.StackTrace); } } // Genres String GENRE_START="ז'אנר:"; String GENRE_INSTANCE_START=""; String GENRE_END="
"; int genrePos = strBody.IndexOf(GENRE_START); if (genrePos >= 0) { genrePos+=GENRE_START.Length; int genreEndPos = strBody.IndexOf(GENRE_END, genrePos); if (genreEndPos >= 0) { String genreString = strBody.Substring(genrePos, genreEndPos - genrePos + 1); genrePos = genreString.IndexOf(GENRE_INSTANCE_START); movieDetails.Genre = ""; while (genrePos >= 0) { genrePos+=GENRE_INSTANCE_START.Length; genreEndPos = genreString.IndexOf(GENRE_INSTANCE_END, genrePos); if (genreEndPos >= 0) { String genre = genreString.Substring(genrePos, genreEndPos - genrePos); movieDetails.Genre+=genre; } genrePos = genreString.IndexOf(GENRE_INSTANCE_START, genrePos); if (genrePos >= 0) { movieDetails.Genre+=" / "; } } } } // Actors String ACTOR_START="